package ldh.im.fxbase.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import ldh.im.fxbase.component.ScreenCapturePane;

import java.net.URL;
import java.util.ResourceBundle;

public class CaptureControlController implements Initializable {

    private ScreenCapturePane screenCapturePane;
//    private WebView webView;

//    public void setWebView(WebView webView) {
//        this.webView = webView;
//    }

    public void setScreenCapturePane(ScreenCapturePane screenCapturePane) {
        this.screenCapturePane = screenCapturePane;
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {

    }

    @FXML public void close(ActionEvent actionEvent) {
        screenCapturePane.hide();
        System.out.println("close!!!!!!!!!!!!");
    }

    @FXML public void square(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.setCanvasType(0);
    }

    @FXML public void circle(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.setCanvasType(1);
    }

    @FXML public void pencil(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.setCanvasType(2);
    }

    @FXML public void text(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.setCanvasType(3);
    }

    @FXML public void eraser(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.setCanvasType(4);
    }

    @FXML public void undo(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
        screenCapturePane.undoCanvas();
    }

    @FXML public void save(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();
    }

    @FXML public void ok(ActionEvent actionEvent) {
        screenCapturePane.stopCapture();

        String captureImage = "file:/" + screenCapturePane.getCaptureImageUrl();

//        String emojiSpan = String.format("<img class='capture' src='%s'>", captureImage);
//        System.out.println("captureImage:" + captureImage + "," + emojiSpan);

        screenCapturePane.callbackForCapture(captureImage);
        screenCapturePane.hide();
    }
}
